<?php
session_start();
//var_dump($_SESSION['topic']);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<!-- 每隔3秒刷新一次本页面 -->
	<meta http-equiv="Refresh" content="2;url=show.php">
	<meta content="text/HTML;charset=utf-8" http-equiv=Content-type>
	<title>显示消息页</title>
	
</head>

<body>
<style>
body{padding:10px;}

</style>
<h1>当前主题为：<strong style="color:red"><?php echo $_SESSION['topic']; ?></strong></h1>


</body>
</html>

<?php

	$conn = @mysql_connect('localhost','root','root') or die("请检查数据库连接是否正确");
	@mysql_select_db("chatroom",$conn) or die("无此数据库");
	@mysql_query("set names utf8");
	
	//向数据库发送查询请求
	$sql = "SELECT * FROM `text`";
	$result = @mysql_query($sql,$conn) or die("浏览失败");
	
	//读取记录数据，分类保存
	$count = 0;
	while($row = mysql_fetch_array($result)){
		$gb[$count]['serial'] = $row['serial'];
		//print_r($row);
		$gb[$count]['name'] = $row['chatname'];
		$gb[$count]['type'] = $row['chattype'];
		$gb[$count]['time'] = $row['chattime'];
		$gb[$count]['text'] = $row['chattext'];
		if($gb[$count]['type'] == 'say'){
			$gb[$count]['emote'] = $row['chatemote'];
		}
		if($gb[$count]['type'] == 'act'){
			$gb[$count]['action'] = $row['chataction'];			
		}
		$count++;
	}
	mysql_close($conn) or die('关闭数据库失败');
	
	//输出发言信息
	for($i=0;$i<$count;$i++){
		//根据发言类型输入相应的方法信息
		$chatstring = null;
		$chatstring .= $gb[$i]['time'];
		$chatstring .= "&nbsp;&nbsp;<strong>".$gb[$i]['name']."</strong>&nbsp;";
		//把各字段信息连接字符串输出
		if($gb[$i]['type'] == "say"){
			$chatstring .= "";
			$tempemote = $gb[$i]['emote'];
			$chatstring .= "<font color=Maroon>".$tempemote."</font>";
			$chatstring .= "&nbsp;说：";
			$chatstring .= $gb[$i]['text'];
		}
		//判断发言类型
		if($gb[$i]['type'] == "act" ){
			$chatstring .= "::";
			$chatstring .= "<font color=green>".$gb[$i]['action']."</font>";
			$chatstring .= "&nbsp;说：";
			$chatstring .= $gb[$i]['text'];
		}
		echo $chatstring."<br />";
	}
	
	
	
	


?>